/**
 * 
 */
package fr.univ_tln.inf9.exaplanning.api.composante;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import fr.univ_tln.inf9.exaplanning.api.db.AbstractEntity;
import fr.univ_tln.inf9.exaplanning.api.db.EntityInfo;
import fr.univ_tln.inf9.exaplanning.api.db.SessionManager;

/**
 * @author emilien
 *
 */
@EntityInfo(	collections = { }, 
				key = "id",
				methods = { "getId", "getTrainingPathName" },
				rows = { "id_group", "name_training_path" },
				table = "groupe", 
				variables = { "trainingPathName" })
public class Group extends AbstractEntity {
	
	private final String id;
	private final String trainingPathName;

	public Group(String id, TrainingPath trainingPath) throws IOException, SQLException {
		super(true);
		this.id = id;
		this.trainingPathName = trainingPath.getName();
	}
	
	private Group(String id, String trainingPath) throws IOException, SQLException {
		super(false);
		this.id = id;
		this.trainingPathName = trainingPath;
	}

	public String getId() {
		return id;
	}

	public String getTrainingPathName() {
		return trainingPathName;
	}
	
	public static Group findByKey(String key) throws IOException, SQLException {
    	List<List<String>> data = SessionManager.getInstance().getData(Group.class, key);
    	
    	List<String> variables = data.get(0);
    	Group result = new Group(variables.get(0), variables.get(1));
    	
    	return result;
	}
	
	
	
}
